package com.generate;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;
import java.util.Collections;

//TODO 待测试
public class CodeGenerate {
    public static void generate(String url, String username, String password) {
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> builder
                                .author("work-generate")
                                .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                                .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.ljh.worksb")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper")
                        .pathInfo(Collections.singletonMap(OutputFile.xml, "/mapper"))
                )
                .strategyConfig(builder -> builder
                        .entityBuilder()
                        .enableLombok()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
